n = input()
combs = {int(n), int(n[:3]), int(n[1:])} | {int(d) for d in n} | {int(n[i:i+2]) for i in range(len(n)-1)}  
n = int(n)
prime = [False, False] + [True] * (n - 1)  
for p in range(2, int(n**0.5) + 1):  
    if prime[p]:  
        for multiple in range(p*p, n + 1, p):  
            prime[multiple] = False  
print(max((i for i in combs if i <= n and prime[i]), default=0))
